app = function(){
	return {init : function(){
		
		Ext.BLANK_IMAGE_URL = 'js/extjs/resources/images/default/s.gif';

		Ext.QuickTips.init();



	//导航区所有面板，添加面板需在此更新
	var westPanelArray = [systemIntro_panel,    			//系统简介
					  baseInfo_panel,monitor_panel];		//基础信息

		//导航面板，采用card布局
		var westPanel = {
			    id: 'westPanel',
			    region: 'west',
			    layout: 'card',
			    border: false,
			    collapsible :true,
			    width: 200,
			    activeItem: 0,
			    items: westPanelArray
			};

	//北区面板

		/**
		* 北区按钮与导航面板联动	
		*/
		function relateHandler(b,e){
			Ext.getCmp('westPanel').layout.setActiveItem(b.relatePanel);
		}

		//定义北区工具栏子模块按钮
		var northPanelBbar = [{
			            text: '操作菜单',
			            iconCls: 'add16',
			            relatePanel:'systemIntro_panel',     //与按钮联动的左边导航面板
			            handler:relateHandler
			        },'-',{
			            text: '基础信息',
			            relatePanel:'baseinfo_panel',        //与按钮联动的左边导航面板
			            iconCls: 'add16',
			            handler:relateHandler
			        },'-',{
			            text: '监测',
			            relatePanel:'monitor_panel',     	 //与按钮联动的左边导航面板
			            iconCls: 'add16',
			            handler:relateHandler
			        }];

		var northPanel = new Ext.Panel({
                	region:'north',
                	margins:'0 0 0 0',
                	height:120,
                	html:'<img src="image/head.jpg"/>',
                	bbar: [northPanelBbar]
            });

	//初始化一些变量 
	var aWeek=['星期天','星期一','星期二','星期三','星期四','星期五','星期六'];

	var clock = new Ext.Toolbar.TextItem(new Date().format('Y-m-d G:i:s A')+'  '+aWeek[new Date().getDay()]);

	//定期更新时间
	Ext.TaskMgr.start({
	  run: function(){
	        Ext.fly(clock.getEl()).update(new Date().format('Y-m-d G:i:s A')+'  '+aWeek[new Date().getDay()]);
	  },
	  interval: 1000
	});

	//南区面板
		var southPanel = new Ext.Panel({
					region:'south',
					margins:'0 0 0 0',
					height:30,
					bbar: ['->',clock]
		});

		// 定义一个TAB页面显示内容
		var tabPanel = new Ext.TabPanel(
				{
					region : "center",
					enableTabScroll : true,
					activeTab : 0,
					autoScroll : true
					
				});


		//总体布局
		new Ext.Viewport({
			layout: 'border',
			id:'viewport',
			items:[westPanel,northPanel,southPanel,tabPanel]
		});

		/**
		 * 设置鼠标单击事件,可以根据自己的需要进行扩展
		 */
		function treeClick(node, e) {
			if (node.isLeaf()) {
				e.stopEvent();
				var n = tabPanel.getComponent(node.id);
				if (!n) {
					var n = tabPanel
							.add( {
								'id' : node.id,
								'title' : node.text,
								closable : true,
								html : '<iframe name="res" src="' + node.attributes.url + '" frameborder="0" scrolling="yes" height="100%" width="100%"></iframe>'
							/*
							 * autoLoad : { url : 'http://www.baidu.com',
							 * scripts : false } //
							 * 通过autoLoad属性载入目标页,如果要用到脚本,必须加上scripts属性
							 */
							});
				}
				tabPanel.setActiveTab(n);
			}
		}

		/**
		*  给每个面板的TreePanel注册节点单击事件
		*/
		var registerTreePanelClickEvent = function (){
			for(var i = 0;i < westPanelArray.length ; i++){
				var p = Ext.getCmp(westPanelArray[i].id);
				for(var j = 0; j < p.items.length; j++){
					p.items.get(j).on('click', treeClick);
				}			
			}
		}();
	}}

}();

Ext.onReady(app.init,app);